package com.hzy.text;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Created by Administrator on 2016/6/17 0017.
 */
public class DBHelper extends SQLiteOpenHelper {
    private static  DBHelper dbHelper = null;

    public static DBHelper getInsrance(Context context){
        if (dbHelper == null) dbHelper =new DBHelper(context);
        return dbHelper;
    }

    private static final String DB_NAME = "scanner.db";
    private static final int DB_VERSION = 1;

    private static final String HISTORY_TABLE_NAME = "history";
    private static final String HISTORY_KEY_RECORD_ID= "_id";
    private static final String HISTORY_KEY_QR_TYPE = "qr_type";
    private static final String HISTORY_KEY_QR_CONTENT = "qr_content";
    private static final String HISTORY_KEY_QR_FROM = "qr_from";
    private static final String HISTORY_KEY_QR_TIME = "qr_time";
    private static final String CREATE_HISTORY_TABLE_SQL = "CREATE TABLE" + HISTORY_TABLE_NAME + " ("
            + HISTORY_KEY_RECORD_ID + "INTEGER PRIMARY KEY AUTOINCREMENT,"
            + HISTORY_KEY_QR_TYPE + " TINYINT,"
            + HISTORY_KEY_QR_CONTENT + "TEXT,"
            + HISTORY_KEY_QR_FROM + " BOOLEAN"
            + HISTORY_KEY_QR_TIME + " DATETIME DEFAULT (datetime('now','localtime')))";

    public DBHelper(Context context) {
        super(context, DB_NAME, null, DB_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
          db.execSQL("CREATE TABLE" + HISTORY_TABLE_NAME + "()");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("drop table if exists"+HISTORY_TABLE_NAME);
        onCreate(db);
    }

    private SQLiteDatabase getDatebase(){
        SQLiteDatabase db = null;
        return db = getWritableDatabase();
    }

    public boolean insertRecord(){
        return true;
    }

}
